<!DOCTYPE html>
<html lang="zh">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>复制符号示例</title>
    <style>
        body {
            font-family: 'Arial', sans-serif;
            background-color: #f4f4f9;
            margin: 0;
            padding: 0;
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }

        .container {
            background-color: #ffffff;
            padding: 30px;
            border-radius: 10px;
            box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
            width: 300px;
            text-align: center;
        }

        h1 {
            font-size: 24px;
            color: #333;
        }

        label {
            font-size: 16px;
            color: #555;
            margin-bottom: 10px;
            display: block;
        }

        input[type="number"] {
            width: 80%;
            padding: 8px;
            margin-bottom: 20px;
            font-size: 16px;
            border: 1px solid #ddd;
            border-radius: 5px;
            text-align: center;
        }

        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 20px;
            border: none;
            border-radius: 5px;
            font-size: 16px;
            cursor: pointer;
            transition: background-color 0.3s ease;
        }

        button:hover {
            background-color: #45a049;
        }

        .result {
            font-size: 18px;
            font-weight: bold;
            color: #333;
            margin-top: 20px;
        }
    </style>
</head>

<body>

    <div class="container">
        <h1>复制符号函数示例</h1>
        <label for="inputX">请输入第一个数字 (x):</label>
        <input type="number" id="inputX" placeholder="输入数字 x" />

        <label for="inputY">请输入第二个数字 (y):</label>
        <input type="number" id="inputY" placeholder="输入数字 y" />

        <button onclick="calculateResult()">计算</button>

        <div class="result" id="result">结果会在这里显示</div>
    </div>

    <script>
        // 定义复制符号函数
        const copySign = (x, y) => (Math.sign(x) === Math.sign(y) ? x : -x);

        // 计算并显示结果
        function calculateResult() {
            const x = parseFloat(document.getElementById("inputX").value);
            const y = parseFloat(document.getElementById("inputY").value);

            if (isNaN(x) || isNaN(y)) {
                document.getElementById("result").textContent = "请输入有效的数字！";
                return;
            }

            const result = copySign(x, y);
            document.getElementById("result").textContent = `结果: ${result}`;
        }
    </script>

</body>

</html>